package com.logicalthinking.socialmall.common.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * 权限枚举类
 */
public enum AuthEnum {

    SYSTEM_MANAGE(1, "系统管理"),
    WECHAT_USER_MANAGE(2, "小程序用户管理"),
    SHOP_APPLY_MANAGE(3, "商家申请"),
    CASH_BACK_MANAGE(4, "返利记录"),
    PRODUCT_MANAGE(5, "商品管理"),
    ORDER_MANAGE(6, "订单管理"),
    WITHDRAW_MANAGE(7, "提现记录"),
    SOCIAL_MANAGE(8, "社交管理"),
    SERVICE_FEE_MANAGE(9, "服务费设置"),
    ;

    //权限值与权限映射关系,方便转化
    private static Map<Integer, AuthEnum> authTypeToAuthEnum = new HashMap<>();
    private static Map<String, AuthEnum> authNameToAuthEnum = new HashMap<>();

    static {
        AuthEnum[] values = AuthEnum.values();
        for (AuthEnum value : values) {
            authTypeToAuthEnum.put(value.getAuthType(), value);
            authNameToAuthEnum.put(value.getAuthName(), value);
        }
    }


    /**
     * 权限类别
     */
    private Integer authType;

    /**
     * 权限名称
     */
    private String authName;

    AuthEnum(Integer authType, String authName) {
        this.authType = authType;
        this.authName = authName;
    }

    public Integer getAuthType() {
        return authType;
    }

    public String getAuthName() {
        return authName;
    }

    /**
     * 将权限值转化为权限枚举类
     *
     * @param authType
     * @return
     */
    public static AuthEnum authTypeTransferToAuthEnum(Integer authType) {
        return authTypeToAuthEnum.get(authType);
    }

    /**
     * 将权限名称转化为权限枚举类
     *
     * @param authName
     * @return
     */
    public static AuthEnum authNameTransferToAuthEnum(String authName) {
        return authNameToAuthEnum.get(authName);
    }
}
